<script setup lang="ts">
import myAxios from '../plugins/myAxios'
import {ref} from 'vue'
import {useRouter} from "vue-router";
import {Toast} from "vant";
const router = useRouter()
const userAccount = ref('')
const userPassword = ref('')
const checkPassword = ref('')
const userPlanet = ref('')
const onSubmit = async () => {
  const res = await myAxios.post('/user/register', {
    userAccount: userAccount.value,
    userPassword: userPassword.value,
    checkPassword: checkPassword.value,
    planetCode: userPlanet.value,
  })
  if (res.code === 0 && res.data) {
    // 跳转到登录页
    router.push('/user/login')
  } else {
    Toast.fail('注册失败');
  }
};



</script>
<template>
  <van-form @submit="onSubmit">
    <van-cell-group inset>
      <van-field
          v-model="userAccount"
          name="userAccount"
          label="账号"
          placeholder="请输入账号"
          :rules="[{ required: true, message: '请填写账号' }]"
      />
      <van-field
          v-model="userPassword"
          type="password"
          name="userPassword"
          label="密码"
          placeholder="请输入密码"
          :rules="[{ required: true, message: '请填写密码' }]"
      />
      <van-field
          v-model="checkPassword"
          type="password"
          name="CheckPassword"
          label="确认密码"
          placeholder="请再次输入密码"
          :rules="[{ required: true, message: '请确认密码' }]"
      />
      <van-field
          v-model="userPlanet"
          name="userPlanet"
          label="星球编码"
          placeholder="请输入星球编码"
          :rules="[{ required: true, message: '请填写编码' }]"
      />
    </van-cell-group>
    <div style="margin: 16px;">
      <van-button round block type="primary" native-type="submit">
        提交
      </van-button>
    </div>
  </van-form>

</template>

<style scoped>

</style>